package com.servlet.user;

import com.enitiy.User;
import com.service.user.UserServiceImpl;

import javax.lang.model.SourceVersion;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 创建作者 ：MySunshine
 * 创建时间 2022/10/24 11:25
 * 项目名称 SHUSHAN
 */
@WebServlet("/userLogin")//用户登录页面后台
public class UserLogin extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String num = req.getParameter("num");
        String pwd = req.getParameter("pwd");
        UserServiceImpl usi = new UserServiceImpl();
        User user = usi.UserLogin(Integer.parseInt(num), pwd);
        System.out.println("num = " + num);
        System.out.println("pwd = " + pwd);
        System.out.println(user);
        if (user!=null){
            String img = user.getImg();
            if (img==null||img.length() <= 0){
                System.out.println(img);
                img="1.jpg";
                user.setImg(img);
            }
            System.out.println("登录成功！");
           req.setAttribute("user",user);
           req.getRequestDispatcher("/page/user/usermain.jsp").forward(req,resp);
        }else {
            System.out.println("登录失败！");
            resp.sendRedirect("/page/user/userLogin.html");
        }
    }
}
